
#include <stdio.h>
#include "wm_hal.h"

#define COM_NUM 4
#define SEG_NUM 12

LCD_HandleTypeDef hlcd;
static void LCD_Test(void);
static void LCD_Init(void);

void Error_Handler(void);

int main(void)
{
	SystemClock_Config(CPU_CLK_160M);
	printf("enter main\r\n");
	
	LCD_Init();
	LCD_Test();
	while (1)
	{
		printf(".");
		HAL_Delay(1000);
	}
}

static void LCD_Test(void)
{
	int i = 0, j = 0;
	
	while(1)
	{
		// 点亮所有的图案
		for(i = 0; i < COM_NUM; i++)
		{
			for(j = 0; j < SEG_NUM; j++)
			{
				HAL_LCD_Write(&hlcd, i, ~(1 << j), (1 << j));
			}
		}
		HAL_Delay(2000);
		
		// 关闭所有图标
		HAL_LCD_Clear(&hlcd);
		HAL_Delay(2000);
		
		// 显示数据123
		HAL_LCD_Write(&hlcd, 1, ~(1 << 1), (1 << 1));
		HAL_LCD_Write(&hlcd, 2, ~(1 << 1), (1 << 1));
		
		HAL_LCD_Write(&hlcd, 0, ~(1 << 3), (1 << 3));
		HAL_LCD_Write(&hlcd, 1, ~(1 << 2), (1 << 2));
		HAL_LCD_Write(&hlcd, 2, ~(3 << 2), (3 << 2));
		HAL_LCD_Write(&hlcd, 3, ~(1 << 3), (1 << 3));
		
		HAL_LCD_Write(&hlcd, 0, ~(1 << 10), (1 << 10));
		HAL_LCD_Write(&hlcd, 1, ~(1 << 10), (1 << 10));
		HAL_LCD_Write(&hlcd, 2, ~(3 << 10), (3 << 10));
		HAL_LCD_Write(&hlcd, 3, ~(1 << 10), (1 << 10));
		HAL_Delay(2000);
	}
}

static void LCD_Init(void)
{
	hlcd.Instance = LCD;
	hlcd.Init.HighDrive = LCD_HIGHDRIVE_1;
	hlcd.Init.Bias = LCD_BIAS_1_3;
	hlcd.Init.Volt = LCD_VOLT_3_3;
	hlcd.Init.Duty = LCD_DUTY_1_4;
	hlcd.Init.Freq = 100;
	hlcd.Init.ComEn = 0xF;
	hlcd.Init.SegEn = 0xFFF;
	
	HAL_LCD_Init(&hlcd);
}

void Error_Handler(void)
{
	while (1)
	{
	}
}

void assert_failed(uint8_t *file, uint32_t line)
{
	printf("Wrong parameters value: file %s on line %d\r\n", file, line);
}